using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControl : MonoBehaviour
{
    private Animator ani;
    private Rigidbody2D rBody;
    void Start()
    {
        ani = GetComponent<Animator>();
        rBody = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        // -1,0,1
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        if(horizontal != 0){
            ani.SetFloat("Horizontal",horizontal);
            ani.SetFloat("Vertical",0);
        }
        if(vertical != 0){
            ani.SetFloat("Horizontal",0);
            ani.SetFloat("Vertical",vertical);
        }
        Vector2 dir = new Vector2(horizontal,vertical);
        ani.SetFloat("Speed",dir.magnitude);
        rBody.velocity = dir * 0.5f;
    }
}
